<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title>登录页面</title>
    <link href="b_css/login.css" rel="stylesheet">
    <link rel="stylesheet" href="b_css/bootstrap.css"/>
    <link href="b_css/base.css" rel="stylesheet">
    <link rel="stylesheet" href="b_css/bootstrapValidator.css"/>
    <link rel="stylesheet" href="b_css/toastr.min.css">

</head>
<body>

    <div class="login_box">
        <div class="b_l"></div>
        <div class="b_r">
            <div class="login">
                <div class="l_top">高校点餐系统</div>
                <!-- <div class="l_username" style="margin-top: 50px;">
                    <div class="user_l">用户名：</div>
                    <div class="user_r"><input type="text" placeholder="请输入用户名" class="form-control" name="username" /></div>
                </div>
                <div class="l_username">
                    <div class="user_l">密码：</div>
                    <div class="user_r"><input type="password" placeholder="请输入密码" class="form-control" name="password" /></div>
                </div> -->
                <form id="defaultForm" method="post" class="form-horizontal" action="target.php" style="margin-top: 50px;">
                    <div class="form-group">
                        <label class="col-lg-3 control-label">用户名：</label>
                        <div class="col-lg-7">
                            <input type="text"  placeholder="请输入用户名" class="form-control" name="username" />
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-lg-3 control-label">密码：</label>
                        <div class="col-lg-7">
                            <input type="password" placeholder="请输入密码" class="form-control" name="password" />
                        </div>
                    </div>
                    <div class="l_username" style="margin-top: 50px;">
                        <div class="user_l"></div>
                        <div class="user_r"><button style="width: 240px;" type="button" class="btn btn-primary">
                            登录</button></div>
                    </div>
                </form>
            </div>
        </div>
    </div>
    <script src="b_js/jquery-3.2.1.min.js"></script>
    <script src="b_js/utils.js"></script>
    <script src="b_js/bootstrap.min.js"></script>
    <script src="b_js/bootstrap-table.js"></script>
    <script src="b_js/bootstrapValidator.js"></script>
    <script src="b_js/bootstrapValidator.min.js"></script>
    <script src="b_js/toastr.min.js"></script>
    <script src="https://unpkg.com/bootstrap-table@1.18.0/dist/locale/bootstrap-table-zh-CN.min.js"></script>
    <script type="text/javascript">
        // function login() {
        //     location.href ="./index.html"
        // }
        function login(){
        //获取表单对象
        var bootstrapValidator = $('#defaultForm').data('bootstrapValidator');
        console.log($('#defaultForm').serialize())
            //手动触发验证
            bootstrapValidator.validate();
            if(bootstrapValidator.isValid()){
                //表单提交的方法、比如ajax提交
            }
        };
        // 新增确认事件
    $(".btn-primary").on("click", function(){
        //获取表单对象
        var bootstrapValidator = $('#defaultForm').data('bootstrapValidator');
            //手动触发验证
            bootstrapValidator.validate();
            if(bootstrapValidator.isValid()){
                $.ajax({
                    type:"get",
                    url: upUrl + "/loginUser?" + $('#defaultForm').serialize(),
                    data: {
                    },
                    success:function(data){
                        console.log(data)
                        if (data.code == 200) {
                            if (data.result.usetype === '0') {
                                toastr.error('非超级管理员不能登录后台');
                            } else {
                                toastr.success("登录成功!");
                                // location.href ="./index.html"
                                setTimeout(function() {
                                    location.href ="./index.html"
                                    window.sessionStorage.setItem('user',JSON.stringify(data.result))
                                }, 500);
                                //用户信息存储起来
                                // window.sessionStorage.setItem('admin', 'admin')
                            }
                        } else {
                            toastr.error(data.message);
                        }
                    }
                })
                // location.href ="./index.html"
                // $.post("{:url('')}", $('#form').serialize(),function (data) {
                //     console.log(data);
                // })
            }
    });
        $(document).ready(function() {
            $('#defaultForm').bootstrapValidator({
                message: 'This value is not valid',
                feedbackIcons: {
                    valid: 'glyphicon glyphicon-ok',
                    invalid: 'glyphicon glyphicon-remove',
                    validating: 'glyphicon glyphicon-refresh'
                },
                fields: {
                    username: {
                        validators: {
                            notEmpty: {
                                message: '请输入用户名'
                            }
                        }
                    },
                    password: {
                        validators: {
                            notEmpty: {
                                message: '请输入你的密码'
                            },
                            // stringLength: {
                            //     min: 1,
                            //     max: 30,
                            //     message: '密码只能是6-30字符'
                            // },
                            // regexp: {
                            //     regexp: /^[a-zA-Z0-9_\.]+$/,
                            //     message: '密码只能包含字母，数字，点和下划线'
                            // },
                        }
                    }
                }
            })
        })
    </script>
</body>
</html>